package com.ecjtu.stadiumre_servations.service.impl;
import com.ecjtu.stadiumre_servations.config.RabbitMQConfig;
import com.ecjtu.stadiumre_servations.entity.domain.Booking;;
import com.ecjtu.stadiumre_servations.response.Result;
import com.ecjtu.stadiumre_servations.service.BookingService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;


@Service
public class RefundResultConsumer {
    @Autowired
    private BookingService bookingService;
    /**
     * 退款消息消费者
     *
     */
    @RabbitListener(queues = RabbitMQConfig.REFUND_RESULT_QUEUE_NAME)
    public Result handleRefundResult(Map<String, String> result) {
        String bookingId = result.get("bookingId");
        String refundStatus = result.get("status");
        Booking booking = bookingService.getById(bookingId);
        if ("SUCCESS".equals(refundStatus)) {
            booking.setBookingStatus("已退款");
            bookingService.updateById(booking);
            return Result.ok("退款成功");
        } else {
            booking.setBookingStatus("退款失败");
            return Result.fail("退款失败");
            // 发送通知给用户或管理员
        }
    }
}